package com.solomiao.demo.multi.thread.demo10;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MainDemo102 {
     private static final Logger LOGGER = LoggerFactory.getLogger(MainDemo102.class);

    private static final Object lock = new Object();

    static void main() throws InterruptedException {
        LOGGER.info("主线程开始运行");
        WaitigRunnable waitigRunnable = new WaitigRunnable();
        Thread t1 = new Thread(waitigRunnable);
        t1.start();
        Thread.sleep(1000);
        LOGGER.info("t1线程的状态：" + t1.getState().toString());
        synchronized (lock) {
            LOGGER.info("主线程准备唤醒等待线程");
            lock.notify();
        }
        Thread.sleep(1000);
        LOGGER.info("t1线程的最终状态：" + t1.getState().toString());
    }

    static class WaitigRunnable implements Runnable {
        @Override
        public void run() {
            LOGGER.info("等待线程开始运行");
            synchronized (lock) {
                LOGGER.info("等待线程进入等待状态");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                LOGGER.info("等待线程被唤醒");
            }
        }
    }
}
